/***********************************************************
 * Product Name: ExcelQuicker
 * Copyright (c)2005, Eunge
 * Author: Eunge
 * Web Site: www.eudev.net
 * Mail/MSN: eudev.net@yeah.net
 * ********************************************************/
using System;

namespace ExcelQuicker.Framework
{
	/// <summary>
	/// Pivot field, stands for a field in pivot table. If you know nothing about pivot, I advise you to study relative knowledge first.
	/// </summary>
	[Serializable]
	public class EQPivotField: EQObject  
	{
		private int mPriority = 1;
		private string mPivotFieldName = "";
		private EQPivotSubtotalsType mSubtotals = new EQPivotSubtotalsType();
		private string mSubtotalsName = "";
		private EQRangeStyle mStyle;
		private EQPivotTableSelectionMode mPivotTableSelectionMode = EQPivotTableSelectionMode.Default;
		private Excel.XlPivotFieldOrientation mPivotFieldOrientation = Excel.XlPivotFieldOrientation.xlHidden;

		/// <summary>
		/// Initialize pivot field from column name of datatable
		/// </summary>
		/// <param name="pivotFieldName">Column name of datatable</param>
		public EQPivotField(string pivotFieldName)
		{
			this.SetPivotFieldName(pivotFieldName);
		}

		/// <summary>
		/// Set/Get subtotal name. 
		/// </summary>
		public string SubtotalsName
		{
			get
			{
				return this.mSubtotalsName;
			}
			set
			{
				if(value.Trim().Length == 0)
					throw new EQException("EQ1015");
				this.mSubtotalsName = value.Trim();
			}
		}

		/// <summary>
		/// Set/Get type of pivot field. Default value is Excel.XlPivotFieldOrientation.xlHidden
		/// </summary>
		public Excel.XlPivotFieldOrientation PivotFieldOrientation
		{
			get
			{
				return this.mPivotFieldOrientation;
			}
			set
			{
				this.mPivotFieldOrientation = value;
			}
		}

		/// <summary>
		/// Set/Get subtotals type
		/// </summary>
		public EQPivotSubtotalsType Subtotals
		{
			get
			{
				return this.mSubtotals;
			}
			set
			{
				this.mSubtotals = value;
			}
		}

		/// <summary>
		/// Set/Get the priority of field. Priority must be more than zero
		/// </summary>
		public int Priority
		{
			get
			{
				return this.mPriority;
			}
			set
			{
				if(value < 1)
					throw new EQException("EQ1016", value.ToString());
				this.mPriority = value;
			}
		}

		/// <summary>
		/// Set/Get style of the range
		/// </summary>
		public EQRangeStyle Style
		{
			get
			{
				return this.mStyle;
			}
			set
			{
				this.mStyle = value;
			}
		}

		/// <summary>
		/// Set pivot name, binding to the corresponding column name of datatable
		/// </summary>
		/// <param name="pivotFieldName"></param>
		protected internal void SetPivotFieldName(string pivotFieldName)
		{
			this.mPivotFieldName = pivotFieldName;
		}

		/// <summary>
		/// Get pivot name, corresponding to the column name of datatable
		/// </summary>
		public string PivotFieldName
		{
			get
			{
				return this.mPivotFieldName;
			}
		}

		/// <summary>
		/// Set/Get mode of pivot field, etc as data field, or as page field. The default value is EQPTSelectionMode.Default
		/// </summary>
		public EQPivotTableSelectionMode PivotTableSelectionMode
		{
			get
			{
				return this.mPivotTableSelectionMode;
			}
			set
			{
				switch(this.PivotFieldOrientation)
				{
					case Excel.XlPivotFieldOrientation.xlDataField:
						if(value != EQPivotTableSelectionMode.LabelOnly)
							return;
						break;
					case Excel.XlPivotFieldOrientation.xlPageField:
						if(value == EQPivotTableSelectionMode.Default)
							return;
						break;
					case Excel.XlPivotFieldOrientation.xlRowField:
						if(value == EQPivotTableSelectionMode.Default)
							return;
						break;
					case Excel.XlPivotFieldOrientation.xlColumnField:
						if(value == EQPivotTableSelectionMode.Default)
							return;
						break;
					default:
						return;
				}
				this.mPivotTableSelectionMode = value;
			}
		}
	}
}
